package com.ht.api.call.func.impl.ad;

import javax.sql.DataSource;

import com.ht.api.bean.AjaxResult;
import com.ht.api.bean.LoginBean;
import com.ht.api.call.func.IFunctionCall;
import com.ht.api.db.Db;
import com.ht.api.db.Entity;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 修改旅程阶段的后置函数
 * @author asq
 * @createTime 2025年3月1日 14:01:20
 */
@Slf4j
public class StageEditFunctionCall implements IFunctionCall {

	@Override
	public String getName() {
		return "修改旅程阶段后置函数";
	}

	@Override
	public JSONObject execute(LoginBean me, JSONObject param, AjaxResult result) {
		DataSource ds = me.getDataSource();

		String stageId = param.getStr("main_id");
		String planId = Db.createSqlParser("stage").select("plan_id").where("main_id", stageId).val(ds);

		Db.insert(ds, Entity.create("ad_plan").set("main_id", planId).set("condition", param.get("condition")));

		return JSONUtil.createObj();
	}
}
